<?php
/**
 * This file is part of Swoft.
 *
 * @link https://swoft.org
 * @document https://doc.swoft.org
 * @contact group@swoft.org
 * @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */

namespace App\Controllers;


use App\Components\Auth;
use App\Components\Handle;
use App\Components\JsonCode;
use App\Components\Tool;
use App\Components\YunClear;
use Swoft\Cache\Cache;
use Swoft\Http\Message\Server\Request;
use Swoft\Http\Server\Bean\Annotation\Controller;
use Swoft\Http\Server\Bean\Annotation\RequestMapping;

/**
 * 回调控制器
 * @Controller(prefix="/check")
 */
class CheckController
{
    /**
     * 图片审核回调
     * @param Request $request
     */
    public function img(Request $request){
        $post = $request->input();
        $app = $post['app']??'';
        $type = $post['type']??'';
        $url = $post['url']??'';
        $uid = $post['uid']??'';
        if (!$app || !$type || !$url || !$uid){
            return JsonCode::Code400('缺少参数');
        }
        $config = config('api.'.$app,[]);
        if (!$config){
            return JsonCode::Code400('app错误');
        }

        if (!Auth::check($config['api_key'],$post)){
            return JsonCode::Code300('鉴权失败');
        }

        $code = YunClear::Img($app,$type,$url,$uid);
        return JsonCode::Code200($code);
    }
    public function text(Request $request){
        Tool::log(time(),'yunjing.log');
        $post = $request->input();
        $app = $post['app']??'';
        $type = $post['type']??'';
        $text = $post['text']??'';
        $uid = $post['uid']??'';
        if (!$app || !$type || !$text || !$uid){
            return JsonCode::Code400('缺少参数');
        }
        $config = config('api.'.$app,[]);
        if (!$config){
            return JsonCode::Code400('app错误');
        }
        if (!Auth::check($config['api_key'],$post)){
            return JsonCode::Code300('鉴权失败');
        }

        $code = YunClear::Slogan($app,$type,$text,$uid);
        return JsonCode::Code200($code);
    }
}